﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using XZL.GM.Bll;

public partial class Admin_User_UserPwd : AdminBasePage
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }


    protected void btnOK_Click(object sender, EventArgs e)
    {
        string pwdOld = CommonMethod.StrToMD5(txtPwdOld.Text.Trim());
        string pwdNew = CommonMethod.StrToMD5(txtPwdNew1.Text.Trim());
        if (pwdOld != AdminUser.Password)
        {
            lblErr.Text = "旧密码输入错误！";
            txtPwdOld.Focus();
            return;
        }
        if (txtPwdNew1.Text.Trim().Length < 6 || txtPwdNew1.Text.Trim().Length > 20)
        {
            lblErr.Text = "请输入6-20位新密码！";
            txtPwdNew1.Focus();
            return;
        }
        if (txtPwdNew2.Text.Trim().Length < 6 || txtPwdNew2.Text.Trim().Length > 20 || txtPwdNew1.Text.Trim() != txtPwdNew2.Text.Trim())
        {
            lblErr.Text = "两次密码输入不一致！";
            txtPwdNew2.Focus();
            return;
        }

       int res = UserInfoBiz.UpdateUserPwd(AdminUser.UserID, pwdOld, pwdNew);
       switch (res)
       {
           case -1:
               {
                   lblErr.Text = "旧密码输入错误！";
                   txtPwdOld.Focus();
                   break;
               }
           case 0:
               {
                   lblErr.Text = "修改成功！";
                   lblErr.ForeColor = System.Drawing.Color.Green;
                   btnOK.Enabled = false;
      
                   Response.Redirect("~/Login.aspx");
                   break;
               }
           default:
               {
                   lblErr.Text = "修改失败，请重试！";
                   break;
               }
       }
    }

}